package com.ledim.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ledim.bean.LedimCardGroupBean;
import com.ledim.bean.LedimChoiceCardBean;
import com.ledim.ledimview.TagsFlowView;
import com.ledim.utils.LedimFunctionUtils;
import com.ledim.utils.LedimViewHolder;
import com.ledim.widget.view.RoundTextView;
import com.letv.android.young.client.R;
import java.util.ArrayList;

/**
 * Created by ccx on 16/7/27.
 * 精选组卡片4adapter tagview
 */
public class CardGroup4Adapter extends CarGroupBaseAdapter {

    private TextView mTitle;
    private TagsFlowView mTagsView;
    private ArrayList<LedimChoiceCardBean> mList;
    ViewGroup.MarginLayoutParams marginLayoutParams;
    View convertView;

    public CardGroup4Adapter(Activity context, LedimCardGroupBean cardGroup) {
        super(context, cardGroup);
        marginLayoutParams =
                new ViewGroup.MarginLayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        marginLayoutParams.setMargins(0, 0, 0, 0);
    }

    @Override
    public void initView(LedimViewHolder viewHolder) {
        mList = new ArrayList<LedimChoiceCardBean>();
        mTitle = viewHolder.getView(R.id.card_a4_title);
        mTitle.setCompoundDrawables(LedimFunctionUtils.getRandomIcon(mActivity), null, null, null);
        mTagsView = viewHolder.getView(R.id.card_a4_flowlayout);
        if (mCardGroupBean != null && mCardGroupBean.cards != null &&
                mCardGroupBean.cards.size() > 0) {
            this.mList.clear();
            this.mList = mCardGroupBean.cards;
            mTitle.setText(mCardGroupBean.title);
            showTagsView();
        }
    }

    //显示标签
    private void showTagsView() {
        mTagsView.removeAllViews();
        //标签边距参数
        for (int i = 0; i < mList.size(); i++) {
            mTagsView.addView(getView(i, convertView), marginLayoutParams);
        }
    }

    public View getView(final int position, View convertView) {
        LedimViewHolder viewHolder =
                LedimViewHolder.get(mActivity, convertView, R.layout.card_a4_item);
        final RoundTextView mNameView = viewHolder.getView(R.id.card_a4_item_tag);
        mNameView.setStrokeColor(LedimFunctionUtils.getRandomColor(mActivity));
        mNameView.setText(mList.get(position).title);
        mNameView.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                LedimFunctionUtils.jumpTargetActivity(mActivity, mList.get(position), mCardGroupBean.id);
            }
        });
        convertView = viewHolder.getConvertView();
        return convertView;
    }

}
